﻿using Assets.Script.Human.Enemy.Actions;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Assets.Script.HelpSystem.AtkSystem
{
    public class PlayerBulletBodyBase:BulletBody
    {
        public bool isMoveSelf = true;
        private int playerID = -1;
        private float dmg;

        public virtual void Init(int playerID, ref float dmg, Vector3 origin, BulletData bulletData,TimeData timeData,Dictionary<Type,int> types)
        {
            BaseInit(origin,bulletData, timeData, types);
            this.dmg = dmg;
            this.playerID = playerID;
            Destroy(transform.parent.gameObject, bulletData.BulletLifeTime * timeData.LocalTimeScale);
        }

        protected virtual void Update()
        {
            if (!isMoveSelf)
                return;
            transform.Translate(Vector3.right * bulletData.BulletSpeed*Time.deltaTime*timeData.LocalTimeScale);
        }



        protected virtual void OnTriggerEnter(Collider other)
        {
            if (other.tag == "Enemy")
            {
                other.gameObject.GetComponent<HumanInterface>().TakeDamage(dmg, 0,0,origin,playerID);
                if (!bulletData.IsThrough)
                {
                    DieEffect(true);
                    Destroy(transform.parent.gameObject);
                }
            }
            else if (other.tag == "Ground")
            {
                if (!bulletData.IsThrough)
                {
                    DieEffect(false);
                    Destroy(transform.parent.gameObject);
                }
            }


        }

        protected virtual void DieEffect(bool hitEnemy)
        {

        }
    }   

    

}
